<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:jsf="http://xmlns.jcp.org/jsf"
      xmlns:p="http://primefaces.org/ui"
      xmlns:c="http://xmlns.jcp.org/jsp/jstl/core">
    <h:head>
    </h:head>

    <h:body>
        <f:metadata>
            <f:viewParam name="dataverseId" value="#{dataverseServiceBean.findRootDataverse().id}"/>
            <f:viewAction action="#{dataverseSession.updateLocaleInViewRoot}"/>
            <f:viewAction action="#{DashboardMoveDataversePage.init}"/>
            <f:viewAction action="#{dataverseHeaderFragment.initBreadcrumbs(dataverseServiceBean.findRootDataverse())}"/>
            <f:viewAction action="#{dataverseHeaderFragment.addBreadcrumb('/dashboard.xhtml'.concat(empty param.dataverseId ? '': '?dataverseId='.concat(param.dataverseId)), bundle['dashboard.title'])}"/> 
            <f:viewAction action="#{dataverseHeaderFragment.addBreadcrumb(bundle['dashboard.move.dataverse.message.summary'])}"/>
        </f:metadata>

        <ui:composition template="/dataverse_template.xhtml">
            <ui:param name="pageTitle" value="#{bundle['dashboard.move.dataverse.header']} - #{dataverseServiceBean.findRootDataverse().name} #{bundle.dataverse}"/>
            <ui:param name="showDataverseHeader" value="false"/>
            <ui:define name="body">
                <h:form id="movedataverse-form" class="form-horizontal">
                    <p:focus for="sourceDataverseMenu"/>
                    <div class="col-md-6">
                        <div class="panel panel-default">
                            <div class="panel-heading text-info">#{bundle['dashboard.move.dataverse.selectdataverse.header']}</div>
                            <div class="panel-body">

                                <!-- dataverse to move: -->
                                <div class="col-xs-12 form-group">
                                    <label for="sourceDataverse" class="col-xs-3 control-label">
                                        #{bundle['dashboard.move.dataverse.label']}
                                    </label>
                                    <div class="col-xs-9">
                                        <p:autoComplete id="sourceDataverseMenu"
                                                        required="true"
                                                        requiredMessage="#{bundle['requiredField']}"
                                                        binding="#{DashboardMoveDataversePage.selectedSourceDataverseMenu}"
                                                        placeholder="#{bundle['dashboard.move.dataverse.placeholder']}"
                                                        multiple="false" scrollHeight="180" forceSelection="true"
                                                        minQueryLength="2" queryDelay="1000" size="36"
                                                        groupBy="#{bundle['dashboard.move.dataverse.menu.header']}"
                                                        emptyMessage="#{bundle['dashboard.move.dataverse.menu.invalidMsg']}"
                                                        value="#{DashboardMoveDataversePage.selectedSourceDataverse}"
                                                        completeMethod="#{DashboardMoveDataversePage.completeSelectedDataverse}"
                                                        var="srcDV" styleClass="DropdownPopup" panelStyleClass="DropdownPopupPanel"
                                                        itemLabel="#{srcDV.alias}" itemValue="#{srcDV}" converter="dataverseConverter">
                                            <p:column>
                                                <h:outputText value="#{srcDV.name}"/>
                                                <h:outputText value=" (#{srcDV.affiliation})" rendered="#{!empty srcDV.affiliation}"/>
                                            </p:column>
                                            <p:column>
                                                <h:outputText value="#{srcDV.alias}"/>
                                            </p:column>
                                            <p:ajax process="@this" event="itemSelect" />
                                            <p:ajax process="@this" event="itemUnselect" />
                                        </p:autoComplete>
                                        <p:message for="sourceDataverseMenu"/>
                                    </div>
                                </div>

                            </div>
                        </div>
                    </div>
                    <div class="col-md-6">
                        <div class="panel panel-default">
                            <div class="panel-heading text-info">#{bundle['dashboard.move.dataverse.newdataverse.header']}</div>
                            <div class="panel-body">
                                
                                <!-- dataverse to move to: -->
                                <div class="col-xs-12 form-group">
                                    <label for="destinationDataverse" class="col-xs-3 control-label">
                                        #{bundle['dashboard.move.dataverse.label']}
                                    </label>
                                    <div class="col-xs-9">
                                        <p:autoComplete id="destinationDataverseMenu"
                                                        required="true"
                                                        requiredMessage="#{bundle['requiredField']}"
                                                        binding="#{DashboardMoveDataversePage.selectedDataverseMenu}"
                                                        placeholder="#{bundle['dashboard.move.dataverse.placeholder']}"
                                                        multiple="false" scrollHeight="180" forceSelection="true"
                                                        minQueryLength="2" queryDelay="1000" size="36"
                                                        groupBy="#{bundle['dashboard.move.dataverse.menu.header']}"
                                                        emptyMessage="#{bundle['dashboard.move.dataverse.menu.invalidMsg']}"
                                                        value="#{DashboardMoveDataversePage.selectedDestinationDataverse}"
                                                        completeMethod="#{DashboardMoveDataversePage.completeSelectedDataverse}"
                                                        var="destDV" styleClass="DropdownPopup" panelStyleClass="DropdownPopupPanel"
                                                        itemLabel="#{destDV.alias}" itemValue="#{destDV}" converter="dataverseConverter">
                                            <p:column>
                                                <h:outputText value="#{destDV.name}"/>
                                                <h:outputText value=" (#{destDV.affiliation})" rendered="#{!empty destDV.affiliation}"/>
                                            </p:column>
                                            <p:column>
                                                <h:outputText value="#{destDV.alias}"/>
                                            </p:column>
                                            <p:ajax process="@this" event="itemSelect" />
                                            <p:ajax process="@this" event="itemUnselect" />
                                        </p:autoComplete>
                                        <p:message for="destinationDataverseMenu"/>
                                    </div>
                                </div>             
                                
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-12 button-block">
                        <p:commandButton id="move" styleClass="btn btn-default" 
                                       value="#{bundle['saveChanges']}"
                                       update="movedataverse-form"
                                       validateClient="true"
                                       oncomplete="if (args &amp;&amp; !args.validationFailed) PF('moveDataverseConfirmation').show();">
                            <!-- if (args &amp;&amp; !args.validationFailed) 
                             prevents the confirm dialog to pop up (client side) if validation fails -->
                        </p:commandButton>
                        <p:button styleClass="btn btn-link" outcome="dashboard" value="#{bundle['cancel']}" />
                    </div>
                    
                    <p:dialog id="moveDataverseConfirmation" header="#{bundle['dashboard.move.dataverse.message.summary']}" widgetVar="moveDataverseConfirmation" modal="true">
                        <p class="text-warning"><span class="glyphicon glyphicon-warning-sign"/> #{bundle['dashboard.move.dataverse.confirm.dialog']}</p>
                        <div class="button-block">
                            <p:commandButton styleClass="btn btn-default" value="#{bundle['dashboard.move.dataverse.confirm.yes']}"
                                             onclick="PF('moveDataverseConfirmation').hide();" 
                                             action="#{DashboardMoveDataversePage.move()}"
                                             update="@form,:messagePanel" partialSubmit="true"/>
                            <button class="btn btn-link" onclick="PF('moveDataverseConfirmation').hide();" type="button">
                                #{bundle.no}
                            </button>
                        </div>
                    </p:dialog>
                </h:form>
            </ui:define>
        </ui:composition>

    </h:body>
</html>
